package com.zzptc.sky.translate;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zzptc.sky.translate.Fragment.TheWordFragment;

public class SettingActivity extends AppCompatActivity {
TextView textView_one,textView_two;
    Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        //回退
        toolbar= (Toolbar) findViewById(R.id.setting_Toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //清除单词本的数据
        findViewById(R.id.setting_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.getInstances().getDaoSession().getEntriesDao().deleteAll();
                TheWordFragment.notifyDataSetChanged();
                Toast toast = Toast.makeText(SettingActivity.this, "已经清空了您的单词本!", Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0, 10); //设置文本的位置，使文本显示靠下一些
                toast.show();
            }
        });
        //版本更新
        textView_one= (TextView) findViewById(R.id.setting_text_one);

                textView_one.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        // 定义一个Toast
                        Toast toast = Toast.makeText(SettingActivity.this, "已经是最新版本!", Toast.LENGTH_LONG);
                        // 定义一个ImageView
                        ImageView imageView = new ImageView(SettingActivity.this);
                        imageView.setImageResource(R.drawable.a2);
                        // 获得Toast的View
                        View toastView = toast.getView();
                        // 定义一个Layout，这里是Layout
                        LinearLayout linearLayout = new LinearLayout(SettingActivity.this);
                        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                        // 将ImageView和ToastView合并到Layout中
                        linearLayout.addView(imageView);
                        linearLayout.addView(toastView);
                        // 替换掉原有的ToastView
                        toast.setView(linearLayout);
                        toast.show();
                    }
                });


        textView_two= (TextView) findViewById(R.id.setting_text_two);
        textView_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingActivity.this,AboutActivity.class);
                startActivity(intent);
            }
        });
    }
}
